package com.yijiaw.interceptor;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.yijiaw.domain.Parttype;
import com.yijiaw.domain.Producttype;
import com.yijiaw.service.ParttypeService;
import com.yijiaw.service.ProducttypeService;

/**
 * 前台页面拦截器，用于加载页面公共数据
 * @author itachi
 *
 */
public class CommonInterceptor extends HandlerInterceptorAdapter {
	
	@Autowired
	ProducttypeService producttypeService;
	
	@Autowired
	ParttypeService parttypeService;
	
	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {

		//产品类型
		List<Producttype> producttypes = producttypeService.findAllProducttypes(0, producttypeService.countProducttypes());
		//配件类型
		List<Parttype> parttypes = parttypeService.findAllParttypes(0, parttypeService.countParttypes());
		
		request.setAttribute("producttypes", producttypes);
		request.setAttribute("parttypes", parttypes);
		
		return true;
	}
	

}
